﻿<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>复选框和文本框的联动效果</title>
  <script type="text/javascript">
    function chk(obj,txtIndex) {
      //获取指定的文本框
      var tmpInput = document.getElementsByName("textfield")[txtIndex];
      //判断文本框是否处于选中状态
      obj.checked?tmpInput.disabled=false:tmpInput.disabled=true;         
    }
  </script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
  <input type="checkbox" name="che" value="" onclick="chk(this,'0')" />
  <input type="text" name="textfield" disabled=true /><br/>
  <input name="che" type="checkbox" value="" onclick="chk(this,'1')"/>
  <input type="text" name="textfield" disabled=true /><br/>
  <input name="che" type="checkbox" value="" onclick="chk(this,'2')"/>
  <input type="text" name="textfield" disabled=true /><br/>
</form>
</body>
</html>